From e80683a8a2933572cace0517e40dcaba1246060f Mon Sep 17 00:00:00 2001 From: "robertlipe@gmail.com" Date: Mon, 14 May 2012 13:44:27 +0000 Subject: [PATCH] Add Tom Paton's change to discard points without timestamps in the track filter. There's the minor detail that it breaks testo. We'll work on that. git-svn-id: http://gpsbabel.googlecode.com/svn/trunk@4174 f51c46e8-681c-474f-0cfe-069cfd0219fb --- .../reference/track/trackfilter_discard.gpx | 31 +++++++++++++++++++ .../track/trackfilter_discard_out.gpx | 26 ++++++++++++++++ gpsbabel/testo.d/track-discard.test | 14 +++++++++ gpsbabel/trackfilter.c | 26 +++++++++++----- .../xmldoc/filters/options/track-discard.xml | 12 +++++++ 5 files changed, 102 insertions(+), 7 deletions(-) create mode 100755 gpsbabel/reference/track/trackfilter_discard.gpx create mode 100644 gpsbabel/reference/track/trackfilter_discard_out.gpx create mode 100644 gpsbabel/testo.d/track-discard.test create mode 100644 gpsbabel/xmldoc/filters/options/track-discard.xml diff --git a/gpsbabel/reference/track/trackfilter_discard.gpx b/gpsbabel/reference/track/trackfilter_discard.gpx new file mode 100755 index 000000000..efe60fd95 --- /dev/null +++ b/gpsbabel/reference/track/trackfilter_discard.gpx @@ -0,0 +1,31 @@ + + + + + + Track 937 + 14/04/2012 3:54 pm + + + 145.411000 + + + + 145.683000 + + + + 145.808000 + + + 145.736000 + + + + + diff --git a/gpsbabel/reference/track/trackfilter_discard_out.gpx b/gpsbabel/reference/track/trackfilter_discard_out.gpx new file mode 100644 index 000000000..3238d0d9e --- /dev/null +++ b/gpsbabel/reference/track/trackfilter_discard_out.gpx @@ -0,0 +1,26 @@ + + + + + + Track 937 + 14/04/2012 3:54 pm + + + 145.411000 + + + + + + 145.736000 + + + + + diff --git a/gpsbabel/testo.d/track-discard.test b/gpsbabel/testo.d/track-discard.test new file mode 100644 index 000000000..91da31aff --- /dev/null +++ b/gpsbabel/testo.d/track-discard.test @@ -0,0 +1,14 @@ +# +# tracks filter merge,discard option tests +# + +rm -f ${TMPDIR}/discard* + +# gpx file with points with missing timestamps (has 4 trkpts, 2 duplicate times, 1 missing time, expect merge to output 2 valid trkpts) +# expecting this to fail during a standard -x track,merge so call directly rather than via gpsbabel function +${PNAME} -t -i gpx -f ${REFERENCE}/track/trackfilter_discard.gpx -x track,merge -o csv -F - && { + echo "$PNAME succeeded! (it shouldn't have with this input...)" +} +# ... but should get through if we discard the points. +gpsbabel -t -i gpx -f ${REFERENCE}/track/trackfilter_discard.gpx -x track,merge,discard -o gpx -F ${TMPDIR}/discard.gpx +compare ${REFERENCE}/track/trackfilter_discard_out.gpx ${TMPDIR}/discard.gpx diff --git a/gpsbabel/trackfilter.c b/gpsbabel/trackfilter.c index f70161f44..140a0eaa1 100644 --- a/gpsbabel/trackfilter.c +++ b/gpsbabel/trackfilter.c @@ -34,6 +34,7 @@ (based on patch from Vladimir Kondratiev) 2007-07-26: Allow 'range' together with trackpoints without timestamp 2010-06-02: Add specified timestamp to each trackpoint (added by sven_luzar) + 2012-05-04: Added 'discard' option to 'merge' to throw out track points without timestamp */ #include @@ -62,6 +63,7 @@ #define TRACKFILTER_TRK2SEG_OPTION "trk2seg" #define TRACKFILTER_SEGMENT_OPTION "segment" #define TRACKFILTER_FAKETIME_OPTION "faketime" +#define TRACKFILTER_DISCARD_OPTION "discard" #undef TRACKF_DBG @@ -81,6 +83,7 @@ static char *opt_seg2trk = NULL; static char *opt_trk2seg = NULL; static char *opt_segment = NULL; static char *opt_faketime = NULL; +static char *opt_discard = NULL; static arglist_t trackfilter_args[] = { @@ -160,6 +163,11 @@ arglist_t trackfilter_args[] = { "Add specified timestamp to each trackpoint", NULL, ARGTYPE_STRING, ARG_NOMINMAX }, + { + TRACKFILTER_DISCARD_OPTION, &opt_discard, + "Discard track points without timestamps during merge", + NULL, ARGTYPE_BOOL, ARG_NOMINMAX + }, ARG_TERMINATOR }; @@ -173,6 +181,7 @@ typedef struct trkflt_s { static trkflt_t *track_list = NULL; static int track_ct = 0; static int track_pts = 0; +static int timeless_pts = 0; static int opt_interval = 0; static int opt_distance = 0; static char need_time; /* initialized within trackfilter_init */ @@ -325,7 +334,8 @@ trackfilter_fill_track_list_cb(const route_head *track) /* callback for track_d track_pts++; wpt = (waypoint *)elem; - if ((need_time != 0) && (wpt->creation_time == 0)) { + if(wpt->creation_time == 0) timeless_pts++; + if (!(opt_merge && opt_discard) && (need_time != 0) && (wpt->creation_time == 0)) { fatal(MYNAME "-init: Found track point at %f,%f without time!\n", wpt->latitude, wpt->longitude); } @@ -483,18 +493,20 @@ trackfilter_merge(void) waypoint *prev, *wpt; route_head *master = track_list[0].track; - if (track_pts < 1) { + if (track_pts-timeless_pts < 1) { return; } - buff = (waypoint **)xcalloc(track_pts, sizeof(*buff)); + buff = (waypoint **)xcalloc(track_pts-timeless_pts, sizeof(*buff)); j = 0; for (i = 0; i < track_ct; i++) { /* put all points into temp buffer */ route_head *track = track_list[i].track; QUEUE_FOR_EACH((queue *)&track->waypoint_list, elem, tmp) { wpt = (waypoint *)elem; - buff[j++] = waypt_dupe(wpt); + if(wpt->creation_time != 0) { + buff[j++] = waypt_dupe(wpt); + } track_del_wpt(track, wpt); waypt_free(wpt); } @@ -504,12 +516,12 @@ trackfilter_merge(void) } track_ct = 1; - qsort(buff, track_pts, sizeof(*buff), trackfilter_merge_qsort_cb); + qsort(buff, track_pts-timeless_pts, sizeof(*buff), trackfilter_merge_qsort_cb); - dropped = 0; + dropped = timeless_pts; prev = NULL; - for (i = 0; i < track_pts; i++) { + for (i = 0; i < track_pts-timeless_pts; i++) { wpt = buff[i]; if ((prev == NULL) || (prev->creation_time != wpt->creation_time)) { route_add_wpt(master, wpt); diff --git a/gpsbabel/xmldoc/filters/options/track-discard.xml b/gpsbabel/xmldoc/filters/options/track-discard.xml new file mode 100644 index 000000000..c654609da --- /dev/null +++ b/gpsbabel/xmldoc/filters/options/track-discard.xml @@ -0,0 +1,12 @@ + +This option is used in conjunction with the merge option to discard track points with missing +timestamps instead of aborting with the "Found track point at lat,lon without time!" error. + + +Merging tracks with missing timestamps with the track filter + +Suppose you want to merge tracks that may have missing timestamps. To do that, use this command line: + +gpsbabel -t -i gpx -f john.gpx -f doe.gpx -x track,merge,discard -o gpx -F john_doe.gpx + + -- 2.30.2